package org.inote.controller;
import org.inote.common.StatusConst;
import org.inote.pojo.tablePojo.Comment;
import org.inote.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/comment")
public class CommentController {


    CommentService commentService;


    @Autowired
    public void setCommentService(CommentService commentService) {
        this.commentService = commentService;
    }

    @ResponseBody
    @RequestMapping("/addComment")
    public String addComment(Integer userId, String content, Integer noteId){
        Comment comment = new Comment(null, userId, content, noteId, new Date());
        boolean result = commentService.addComment(comment);
        if (!result){
            return StatusConst.FALSE;
        }
        return StatusConst.TRUE;
    }

    @ResponseBody
    @RequestMapping("/getCommentByNoteId")
    public List<Comment> getCommentByNoteId(Integer commentNoteId, Model model){
        System.out.println(commentNoteId);
        List<Comment> comments = commentService.queryNoteComments(commentNoteId);
        return comments;
    }
}
